//
// Created by GF on 2023/10/27.
//

#ifndef RECORD_NODELIST_H
#define RECORD_NODELIST_H

/* Field NodeList 节点 (Node) 结构 */
struct Field_Node {

    int Idx; /* Field索引(Index) */
    char Name[32]; /* Field名称(Name) */
    char Type[16]; /* 类型(Type) */
    char StrVal[32]; /* 字符串值(String Value) */
    int IntVal; /* 整数值(Integer Value) */
    double DecVal; /* 小数值(Decimal Value) */
    /* ********************************************** */
    struct Field_Node* Prev; /* Matrix Nodelist 的前一节点 */
    struct Field_Node* Next; /* Matrix Nodelist 的下一节点 */
};

/* Record NodeList 节点 (Node) 结构 */
struct Record_Node {

    int Idx; /* Record索引(Index) */
    /* ********************************************** */
    struct Field_Node* Field;
    /* ********************************************** */
    struct Record_Node* Prev; /* Matrix Nodelist 的前一节点 */
    struct Record_Node* Next; /* Matrix Nodelist 的下一节点 */
};

/* Field NodeList 节点(Node)初始化 */
struct Field_Node* Field_NodeList_Node_Init();

/* Record NodeList 节点(Node)初始化 */
struct Record_Node* Record_NodeList_Node_Init();

/* ************************************************** */

/* Field NodeList 获取字段(Field)最大索引 */
int Field_NodeList_Get_Max_Index(struct Field_Node* Field_Head);

/* Field NodeList 判断字段(Field)存在某个索引(Index) */
int Field_NodeList_Judge_Exists_Idx(struct Field_Node* Field_Head, int FldIdx);

/* Field NodeList 判断字段(Field)存在某个字段名 */
int Field_NodeList_Judge_Exists_FldName(struct Field_Node* Field_Head, char* Field_Name);

/* Field NodeList 字段末尾添加字段(Field) */
void Field_NodeList_Append_Field(struct Field_Node* Field_Head, char* Field_Name);

/* Field NodeList 字段末尾添加字段(Field) - 指定索引(Index) */
void Field_NodeList_Append_Field_Alloc_Idx(struct Field_Node* Field_Head, char* FldName, int FldIdx);

/* Field NodeList 复制字段(Field)值 - 通过字段名复制 */
void Field_NodeList_Copy_FldVals_By_FldName(struct Field_Node* Dst_Head, char* Dst_FldName, struct Field_Node* Src_Head, char* Src_FldName);

/* Field NodeList 查找字段String值 - 通过字段名查找 */
char* Field_NodeList_Find_StrVal_By_FldName(struct Field_Node* Field_Head, char* Field_Name);

/* Field NodeList 查找字段Decimal值 - 通过字段名查找 */
double Field_NodeList_Find_DecVal_By_FldName(struct Field_Node* Field_Head, char* Field_Name);

/* Field NodeList 字段(Field)名称格式化输出 */
void Field_NodeList_FldName_Format_Print(struct Field_Node* Field_Head);

/* Field NodeList 字段(Field)名称格式化输出为CSV */
void Field_NodeList_FldName_Format_Print_As_Csv(struct Field_Node* Field_Head, char* Out_Path);

/* Field NodeList 字段(Field)值格式化输出 */
void Field_NodeList_FldVal_Format_Print(struct Field_Node* Field_Head);

/* Field NodeList 字段(Field)值格式化输出为CSV */
void Field_NodeList_FldVal_Format_Print_As_Csv(struct Field_Node* Field_Head, char* Out_Path);

/* ************************************************** */

/* Record NodeList 获取记录(Record)最大索引 */
int Record_NodeList_Get_Max_Index(struct Record_Node* Record_Head);

/* Record NodeList 获取记录(Record)行数 */
int Record_NodeList_Get_Rows_Number(struct Record_Node* Record_Head);

/* Record NodeList 获取字段(Field)索引(Index) - 通过字段名获取 */
int Record_NodeList_Get_FldIdx_By_FldName(struct Record_Node* Record_Head, char* Field_Name);

/* Record NodeList 判断记录(Record)存在某个索引(Index) */
int Record_NodeList_Judge_Exists_Idx(struct Record_Node* Record_Head, int RecIdx);

/* Record NodeList 刷新字段(Field)到所有记录 */
void Record_NodeList_Flush_Field_To_All_Rec(struct Record_Node* Record_Head);

/* Record NodeList 记录末尾添加记录(Record) */
void Record_NodeList_Append_Record(struct Record_Node* Record_Head);

/* Record NodeList 记录末尾添加记录(Record) - 指定索引(Index) */
void Record_NodeList_Append_Record_Alloc_Idx(struct Record_Node* Record_Head, int RecIdx);

/* Record NodeList 按索引更新字符串(String)值 */
void Record_NodeList_Update_StrVal_By_Idx(struct Record_Node* Record_Head, int RecIdx, int FldIdx, char* Value);

/* Record NodeList 按索引更新小数(Decimal)值 */
void Record_NodeList_Update_DecVal_By_Idx(struct Record_Node* Record_Head, int RecIdx, int FldIdx, double Value);

/* Record NodeList 按字段名称更新字符串(String)值 */
void Record_NodeList_Update_StrVal_By_FldName(struct Record_Node* Record_Head, int RecIdx, char* FldName, char* Value);

/* Record NodeList 按字段名称更新小数(Decimal)值 */
void Record_NodeList_Update_DecVal_By_FldName(struct Record_Node* Record_Head, int RecIdx, char* FldName, double Value);

/* Record NodeList 查找记录Decimal值 - 通过字段名查找 */
double Record_NodeList_Find_DecVal_By_FldName(struct Record_Node* Record_Head, int RecIdx, char* FldName);

/* Record NodeList 按索引删除(Delete)记录(Record) */
void Record_NodeList_Delete_Record_By_Idx(struct Record_Node* Record_Head, int RecIdx);

/* Record NodeList 重置记录(Record)索引(Index) */
void Record_NodeList_Reset_Record_Idx(struct Record_Node* Record_Head);

/* Record NodeList 冒泡排序(Bubble Sort Asc) - 按字段名 */
void Record_NodeList_Bubble_Sort_Asc_By_FldName(struct Record_Node* Record_Head, char* FldName);

/* Record NodeList 冒泡排序(Bubble Sort Desc) - 按字段名 */
void Record_NodeList_Bubble_Sort_Desc_By_FldName(struct Record_Node* Record_Head, char* FldName);

/* Record NodeList 从二维指针数组载入字段值(FldVal) */
void Record_NodeList_Load_FldVal_From_TwoDimPtrArr(struct Record_Node* Record_Head, char* FldName, char*** TwoDimPtrArr, int ArrCol);

/* Record NodeList 字段(Field)值类型转换 */
void Record_NodeList_FldVal_Type_Convert(struct Record_Node* Record_Head, char* FldName, char* Type);

/* Record NodeList 记录(Record)格式化输出 */
void Record_NodeList_Record_Format_Print(struct Record_Node* Record_Head);

/* Record NodeList 记录(Record)格式化输出为CSV */
void Record_NodeList_Record_Format_Print_As_Csv(struct Record_Node* Record_Head, char* Out_Path);

/* Record NodeList 复制所有记录(Record) */
struct Record_Node* Record_NodeList_Copy_All_Record(struct Record_Node* Src_Record);

/* Record NodeList 创建系列(Series)记录 */
struct Record_Node* Record_NodeList_Create_Series(char* FldName, int RowsNum);

/* Record NodeList 通过字段(Field)名称提取系列(Series)记录 */
struct Record_Node* Record_NodeList_Extract_Series_By_FldName(struct Record_Node* Record_Head, char* FldName);

/* Record NodeList 左连接(Left Join) - 按索引(Index) */
struct Record_Node* Record_NodeList_Left_Join_On_RecIdx(struct Record_Node* Left_Rec, struct Record_Node* Right_Rec, char* Suffixes);

/* Record NodeList 左连接(Left Join) - 按字段名 */
struct Record_Node* Record_NodeList_Left_Join_On_FldName(struct Record_Node* Left_Rec, struct Record_Node* Right_Rec, char* On_FldName);

#endif //RECORD_NODELIST_H

/*
 * 缩写约定:
 *
 * analysis : anal
 * characteristic : chara
 * compute : cmpt
 * current : cur
 * distance : dis
 * member : mem
 * original : org
 * other : oth
 * probability : prob
 * quantity : qty
 * sample : spl
 * sequence : seq
 * statistics : stats
 *
 * T+0(Transaction plus 0 days), 是证券交易与结算制度的一种简称. 在学术研究和实际业务中, T+0又可以细分为T+0交易制度和T+0结算制度.
 *
 * My Stock Field:
 *
 * 01.日期 : Date
 * 02.名称 : Name
 * 03.代码 : Code
 * 04.开盘价 : Open
 * 05.最高价 : High
 * 06.最低价 : Low
 * 07.收盘价 : Close
 * 08.前收盘 : Pre_Close (Previous Close)
 * 09.涨跌额 : Rise_Fall_Amt (Rise and Fall Amount)
 * 10.涨跌率 : Rise_Fall_Rate (Rise and Fall Rate)
 * 11.换手率 : Turnover_Rate (Turnover Rate)
 * 12.成交量 : Volume
 * 13.成交额 : Trading_Volumes (Trading Volumes)
 * 14.总市值 : Market_Cap (Market Cap)
 * 15.流通市值 : Circ_Market_Value (Circulation Market Value)
 *
 * 163股票字段:
 *
 * 开盘价 : TOPEN
 * 最高价 : HIGH
 * 最低价 : LOW
 * 收盘价 : TCLOSE
 * 前收盘价 : LCLOSE
 * 涨跌额 : CHG (Change)
 * 涨跌幅 : PCHG (Price Change)
 * 换手率 : TURNOVER
 * 成交量 : VOTURNOVER
 * 成交金额 : VATURNOVER
 * 总市值 : TCAP
 * 流通市值 : MCAP
 *
 */
